package jianzhi

func lengthOfLongestSubstring(s string) int {

	indexMap := make(map[rune]int)

	max, cur := 0, 0

	for i, v := range s {
		if _, ok := indexMap[v]; !ok {
			indexMap[v] = i
			cur++
		} else {
			if cur > max {
				max = cur
			}
			cur = i - indexMap[v]
		}
		indexMap[v] = i
	}

	if cur > max {
		max = cur
	}

	return max
}
